package com.gagakuai.demo.registrytest;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/*
 * @program: settement
 * @description:
 * @author: houhong
 * @create: 2022-11-12 18:09
 */
public class ServiceContext {

    public Map<String, AbstractService> serviceMap = new ConcurrentHashMap<>(16);


    public ServiceContext(Map<String, AbstractService> serviceMap) {
        this.serviceMap = serviceMap;
    }

    public void addService(String name, AbstractService abstractService) {
        serviceMap.put(name, abstractService);
    }


    public Map<String, AbstractService> getServiceMap() {
        return serviceMap;
    }

    public void setServiceMap(Map<String, AbstractService> serviceMap) {
        this.serviceMap = serviceMap;
    }

    /*
     * 获得处理的世列
     *
     * @param type
     * @return
     */
    public AbstractService getInstance(String type) throws Exception {
        if (type == null) {
            throw new Exception("没有值");
        }
        AbstractService clazz = serviceMap.get(type);
        if (clazz == null) {
            throw new Exception("没有值");
        }
        return clazz;
    }
}